//
//  SNFmdbManager.h
//  app
//
//  Created by 王少宁 on 15/4/29.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface SNResultSet : NSObject

@property (nonatomic, assign, readonly) NSUInteger rowCount; // 行数
@property (nonatomic, assign, readonly) NSUInteger columnCount; // 列数
@property (nonatomic, strong, readonly) NSArray *allColumnName;
@property (nonatomic, assign, readonly) BOOL hasNext;

- (instancetype)initWithDataArray:(NSArray *)dataArray columnNameToIndexMap:(NSDictionary *)columnNameToIndexMap;

- (NSInteger)columnIndexForName:(NSString *)columnName;
- (NSString *)columnNameForIndex:(NSInteger)columnIndex;

- (NSInteger)intForColumn:(NSString *)columnName;
- (NSInteger)intForColumnIndex:(NSInteger)columnIndex;

- (long)longForColumn:(NSString *)columnName;
- (long)longForColumnIndex:(NSInteger)columnIndex;

- (long long)longLongIntForColumn:(NSString *)columnName;
- (long long)longLongIntForColumnIndex:(NSInteger)columnIndex;

- (BOOL)boolForColumn:(NSString *)columnName;
- (BOOL)boolForColumnIndex:(NSInteger)columnIndex;

- (double)doubleForColumn:(NSString *)columnName;
- (double)doubleForColumnIndex:(NSInteger)columnIndex;

- (NSString *)stringForColumn:(NSString *)columnName;
- (NSString *)stringForColumnIndex:(NSInteger)columnIndex;

- (NSDate *)dateForColumn:(NSString *)columnName;
- (NSDate *)dateForColumnIndex:(NSInteger)columnIndex;

- (NSData *)dataForColumn:(NSString *)columnName;
- (NSData *)dataForColumnIndex:(NSInteger)columnIndex;

- (id)objectForColumnName:(NSString *)columnName;
- (id)objectForColumnIndex:(NSInteger)columnIndex;

- (BOOL)columnIsNullColumnName:(NSString *)columnName;
- (BOOL)columnIsNullForIndex:(NSInteger)columnIndex;

@end






@interface SNFmdbManager : NSObject

+ (SNFmdbManager *)shareManager;

@property (nonatomic,retain) FMDatabaseQueue * fmdbQueue;

//是否自动刷新
- (BOOL)shouldRefreshSelfWithLastRequestTime:(NSDate *)lastRequestDate refreshSelfTimeInterval:(float)timeInterval tableName:(NSString *)tableName;
//创建表
- (BOOL)createTableWithSql:(NSString *)sql;
- (BOOL)createTableWithTableName:(NSString *)tableName;
//表是否存在
- (BOOL)fmdbIncludetableWithTableName:(NSString *)tableName;
//表中是否存有数据
- (BOOL)tabelIncludeDataWithTableName:(NSString *)tableName;
//删除表
- (BOOL)deletetableWithTableName:(NSString *)tableName;
//将数据保存到表
- (BOOL)saveDataToTableWithData:(NSData*)data tableName:(NSString *)tableName;
//从表中读取数据
- (NSData *)dataFromTableWithTableName:(NSString *)tableName;
-(NSMutableArray*)dataFromTable:(NSString*)tableName;
- (NSMutableArray *)arrayFromFmdbWithArray:(NSMutableArray *)maArray;

//执行 sql 的 executeUpdate 语句
- (BOOL)performExecuteUpdateWithSql:(NSString *)sql;
- (BOOL)performExecuteUpdateWithSql:(NSString *)sql withArguments:(NSArray *)arguments;
//执行 sql 的 executeQuery 语句
- (SNResultSet *)performExecuteQueryWithSql:(NSString *)sql;
- (SNResultSet *)performExecuteQueryWithSql:(NSString *)sql withArguments:(NSArray *)arguments;

@end
